package com.scuec.tourismwebsite.mapper;
import com.scuec.tourismwebsite.entity.City;
import com.scuec.tourismwebsite.vo.ViewWeatherForecastWithCity;
import com.scuec.tourismwebsite.entity.WeatherForecast;
import org.apache.ibatis.annotations.*;
//
import java.util.Date;
import java.util.List;
@Mapper
public interface WeatherForecastMapper {

    @Select("select wf.forecast_id,c.city_id,c.city_name, c.province, wf.forecast_date, " +
            "wf.max_temperature, wf.min_temperature, wf.wind_force, " +
            "wf.weather_condition, wf.create_date " +
            "from weather_forecast wf join city c on wf.city_id = c.city_id " +
            "group by c.city_id, wf.forecast_date " +
            "order by c.city_id ASC, wf.forecast_date ASC")
    List<ViewWeatherForecastWithCity> findWeatherForecastWithCity();


    @Insert("insert into weather_forecast (city_id, forecast_date, max_temperature, min_temperature," +
            "wind_force, weather_condition,create_date)" +
            "values (#{city_id}, #{forecast_date}, #{max_temperature}, #{min_temperature}," +
            " #{wind_force}, #{weather_condition},#{create_date})")
    Integer insertWeatherForecast(WeatherForecast weatherForecast);


    @Update("update weather_forecast set city_id = #{city_id}, forecast_date = #{forecast_date}," +
            "max_temperature = #{max_temperature}," +
            "min_temperature = #{min_temperature}," +
            "wind_force = #{wind_force}," +
            "weather_condition = #{weather_condition}," +
            "create_date = #{create_date} " +
            "where forecast_id = #{forecast_id}")
    Integer updateWeatherForecast(WeatherForecast weatherForecast);


    @Delete("delete from weather_forecast where forecast_id = #{forecast_id}")
    Integer deleteWeatherForecast(Integer forecast_id);


    /*
    @Select("select * from city where city_name like concat('%', #{city_name}, '%')and province like concat('%', #{province}, '%')")
    List<City> findCityID(String city_name, String province);*/
   /*
    @Select("select * from weather_forecast order by forecast_id")
    List<WeatherForecast> findWeatherForecastAll();*/


    /*
    @Select("select * from weather_forecast where forecast_id = #{forecastId}")
    WeatherForecast findWeatherForecastByID(Integer forecastId);*/

    /*前端写好了代码，后端不需要的
    @Select("SELECT wf.forecast_id, c.city_name, c.province, wf.forecast_date, wf.max_temperature, wf.min_temperature, wf.wind_direction, wf.wind_force, wf.weather_condition, wf.sports_index, wf.sports_advice, wf.clothing_index, wf.clothing_advice, wf.tourism_index, wf.tourism_advice, wf.create_date FROM weather_forecast wf JOIN city c ON wf.city_id = c.city_id WHERE (c.city_name LIKE CONCAT('%', #{city_name}, '%') OR #{city_name} IS NULL) AND (c.province LIKE CONCAT('%', #{province}, '%') OR #{province} IS NULL) AND (wf.forecast_date = #{forecast_date} OR #{forecast_date} IS NULL)\n" )

    List<ViewWeatherForecastWithCity> findWeatherForecastByCityAndDate(@Param("city_name") String city_name, @Param("province") String province, @Param("forecast_date") Date forecast_date);

     */
}